package com.example.bgImageSear;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

@Configuration
public class SwaggerConfig {
    //配置了Swagger的Docket的Bean实例
    @Bean
    public Docket docket(Environment environment){

        Profiles profiles = Profiles.of("dev");
        //获取项目环境
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("rmg")
                .enable(flag) //是否启动Swagger
                .select()
                //RequestHandlerSelectors,配置要扫描接口的方式
                //basePackage：指定要扫描的包
                //any（）：扫描全部//
                // 过滤.paths();
                .apis(RequestHandlerSelectors.basePackage("com.example.bgImageSear.user.controller"))
                .build();
    }
    //    配置Swaggr信息=apiInfo
    private ApiInfo apiInfo(){
        Contact contact =new Contact("rmg", "http://127.0.0.1:5173/", "2051055446@qq.com");
        return new ApiInfo(
                "RMG的Swagger",
                "This is a sample REST API",
                "1.0",
                "Terms of service",
                contact,
                "License of API",
                "API license URL",
                new ArrayList()
        );
    }
}
